﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using DAL;
using DAL.Service;
using DAL.Service.Impl;
using System.Data;
using DomainModel;

namespace BIZ
{
    public class BookOper
    {
        IBookService bookOper = new BookServiceImpl();
        BorrowBooksRule bookRule = new BorrowBooksRule();
        /// <summary>
        /// 到期提醒
        /// </summary>
        /// <returns></returns>
        public IList getExpireRemind()
        {
            return bookOper.getExpireRemind();
        }
        /// <summary>
        /// 还书提醒
        /// </summary>
        /// <returns></returns>
        public IList getReturnRemind()
        {
            return bookOper.getReturnRemind();
        }
        public IList userGetRemind(int uid)
        { 
            return bookOper.userGetRemind(uid);
        }

        /// <summary>
        /// 已归还的图书
        /// </summary>
        /// <param name="bookname"></param>
        /// <param name="in_s"></param>
        /// <param name="in_e"></param>
        /// <param name="pageno"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList getReturnBooks(string bookname, string in_s, string in_e, int pageno, int pagesize)
        {
            return bookOper.getReturnBooks(bookname, in_s, in_e, pageno, pagesize);
        }
        /// <summary>
        /// 借出图书查询
        /// </summary>
        /// <param name="bookname"></param>
        /// <param name="in_s"></param>
        /// <param name="in_e"></param>
        /// <param name="pageno"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList getloanBooks(string bookname, string in_s, string in_e, int pageno, int pagesize)
        {
            return bookOper.getloanBooks(bookname, in_s, in_e, pageno, pagesize);
        }

        /// <summary>
        /// 新入库图书查询
        /// </summary>
        /// <param name="bookname"></param>
        /// <param name="in_s"></param>
        /// <param name="in_e"></param>
        /// <param name="pageno"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList getputInStorage(string bookname, string in_s, string in_e, int pageno, int pagesize)
        {
            return bookOper.getputInStorage(bookname, in_s, in_e, pageno, pagesize);
        }


        /// <summary>
        /// 保存图书信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public object save(object entity)
        {
            return bookOper.save(entity);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="bookName">书名</param>
        /// <param name="translatedName">译名</param>
        /// <param name="language">语种</param>
        /// <param name="ebook">电子或图书</param>
        /// <param name="forAge">适读年龄</param>
        /// <param name="level">级别</param>
        /// <param name="bookType">类型</param>
        /// <param name="bookTheme">主题</param>
        /// <param name="author">作者</param>
        /// <param name="press">出版社</param>
        /// <param name="in_s">添加时间结束</param>
        /// <param name="in_e">添加时间开始</param>
        /// <param name="pageno">页码</param>
        /// <param name="pagesize">每页条数</param>
        /// <returns></returns>
        public IList getLibraryBookist(string bookName, string translatedName, int language, int ebook,
            int forAge, int level, int bookType, int bookTheme, string author, string press,
            string in_s, string in_e, int state, int pageno, int pagesize, string isbn, string selbookaboutcd, string txtbookcount, string txtbooksum, string txtbsum, string txtwhere, string txtjiage, string olb_bookName, string olb_ebook, string olb_forAge, string olb_level, string olb_bookType, string olb_bookTheme, string olb_booksCount, string olb_inventory, string olb_position, string olb_price, string olb_state, string olb_id)
        {
            return bookOper.getLibraryBookist(bookName, translatedName, language, ebook, forAge, level, bookType, bookTheme, author, press, in_s, in_e, state, pageno, pagesize, isbn, selbookaboutcd, txtbookcount, txtbooksum, txtbsum, txtwhere, txtjiage, olb_bookName, olb_ebook, olb_forAge, olb_level, olb_bookType, olb_bookTheme, olb_booksCount, olb_inventory, olb_position, olb_price, olb_state, olb_id);
        }
        public IList getBookDetaillist(string bookName, string translatedName, int language, int ebook,
    int forAge, int level, int bookType, int bookTheme, string author, string press,
    string in_s, string in_e, int state, int pageno, int pagesize, string isbn, string selbookaboutcd, string txtwhere, string txtjiage, string olb_bookName, string olb_ebook, string olb_forAge, string olb_level, string olb_bookType, string olb_bookTheme, string olb_state, string olb_id, string olbd_isbn, string olb_translatedName, string olb_language, string jc_s, string jc_e, string gh_s, string gh_e, string selmp3)
        {
            return bookOper.getBookDetaillist(bookName, translatedName, language, ebook, forAge, level, bookType, bookTheme, author, press, in_s, in_e, state, pageno, pagesize, isbn, selbookaboutcd, txtwhere, txtjiage, olb_bookName, olb_ebook, olb_forAge, olb_level, olb_bookType, olb_bookTheme, olb_state, olb_id, olbd_isbn, olb_translatedName, olb_language, jc_s, jc_e, gh_s, gh_e, selmp3);
        }
        /// <summary>
        /// 根据id查询图书信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IList getLibraryBookbyid(int id)
        {
            return bookOper.getLibraryBookbyid(id);
        }

        public IList getisbnborrowlist(int lbdid)
        {
            return bookOper.getisbnborrowlist(lbdid);
        }

        public IList getBooklist(string name, string author, string isbn)
        {
            return bookOper.getBooklist(name, author, isbn);
        }

        public IList getLibraryBookId(int detailId)
        {
            return bookOper.getLibraryBookId(detailId);
        }
        /// <summary>
        /// 修改图书状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int updateBookState(int id, int state)
        {
            return bookOper.updateBookState(id, state);
        }
        /// <summary>
        /// isbn是否有重复
        /// </summary>
        /// <param name="isbn"></param>
        /// <returns></returns>
        public int isbnCount(string isbn)
        {
            return bookOper.isbnCount(isbn);
        }
        /// <summary>
        /// 图书总量、库存量审核
        /// </summary>
        public void booksCountJs(string lbid, int user)
        { 
            bookOper.booksCountJs(lbid,user);
        }
        /// <summary>
        /// 修改isbn状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int updateIsbnBookState(int id, int state)
        {
            return bookOper.updateIsbnBookState(id, state);
        }
        /// <summary>
        /// 根据id删除图书信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int deleteLibraryBook(int id)
        {
            return bookOper.deleteLibraryBook(id);
        }

        /// <summary>
        /// 库存量+1
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int addInventOry(int id)
        {
            return bookOper.addInventOry(id);
        }

       
        /// <summary>
        /// 借阅排行
        /// </summary>
        /// <returns></returns>
        public IList jyRanking()
        {
            return bookOper.jyRanking();
        }
        /// <summary>
        /// 收藏排行
        /// </summary>
        /// <returns></returns>
        public IList saveRanking()
        {
            return bookOper.saveRanking();
        }

        /// <summary>
        /// 借过指定图书的家长
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IList getUserNameByBookId(int id)
        {
            return bookOper.getUserNameByBookId(id);
        }

        /// <summary>
        /// 指定图书的评价
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IList getappraisal(int id)
        {
            return bookOper.getappraisal(id);
        }


        public IList getBookist(string text, int language, int ebook,
             int forAge, int level, int bookType, int bookTheme, int cd, int mp3, int inventory, int pageno, int pagesize)
        {
            return bookOper.getBooklist(text, language, ebook, forAge, level, bookType, bookTheme, cd, mp3, inventory, pageno, pagesize);
        }
        public IList getbookIsbnList(string lbid)
        {
            return bookOper.getbookIsbnList(lbid);
        }

        public IList getBookIdIsbn(string bookname)
        {
            return bookOper.getBookIdIsbn(bookname);
        }

        public IList getBookDetailId(int id)
        {
            return bookOper.getBookDetailId(id);
        }
        /// <summary>
        /// 借书
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="bookid"></param>
        /// <returns></returns>
        public string indent(int uid, int bookid, string isbn)
        {
            //1.判断是否符合借书条件
            int ucid = 0;//会员卡id            
            string str = bookRule.validationUser(uid, 1);//判断该用户是否符合借书条件
            if (str == "best4")
                return "best4";//最多4本
            else if (str == "notimes")
                return "notimes";//无剩余次数
            else if (str == "nocard")
                return "nocard";//没充值卡
            int f = bookRule.validationBooks(bookid);//验证图书是否符合出借标准
            if (f == 0)
                return "nobook";
            else if (f == 1)
                return "nonum";
            else if (f == 2)
                return "dzs";
            if (str.StartsWith("good"))
            {
                string[] arr = str.Split(',');
                ucid = int.Parse(arr[1].ToString());
            }

            return "y";
        }

        /// <summary>
        ///  //2.图书表图书库存量-1（借几本图书id修改几条）
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int subtractInventOry(int id)
        {
            return bookOper.subtractInventOry(id);
        }
        /// <summary>
        /// 3.根据图书id和isbn号修改图书明细表图书借出状态（借几个isbn修改几条记录）
        /// </summary>
        /// <param name="bookid"></param>
        /// <param name="isbn"></param>
        /// <param name="state">(int)DAL.Enums.isbnstate.借出</param>
        /// <returns></returns>
        public int updateBookDetailState(int bookid, string isbn, int state)
        {
            return bookOper.updateBookDetailState(bookid, isbn, state);
        }



        /// <summary>
        /// //5.订单明细表添加明细（借几个isbn几条记录）
        /// </summary>
        /// <param name="indentId"></param>
        /// <param name="bookdetailId"></param>
        public void saveIndentDetail(int indentId, int bookdetailId)
        {
            LibraryBookIndentDetail indentDetail = new LibraryBookIndentDetail();
            indentDetail.lbid_lbiid = indentId;
            indentDetail.lbid_lbdid = bookdetailId;//图书明细表id 
            save(indentDetail);
        }
        ////6.添加订单变更记录（一条）
        public void saveIndentLog(int indentid, int oldState, int newState, int user)
        {
            IndentOperationLog log = new IndentOperationLog();

            log.iol_iblid = indentid;//订单id
            log.iol_oldState = (byte)oldState;//	原状态
            log.iol_nowState = (byte)newState;//	当前状态
            log.iol_time = DateTime.Now;//	变更时间
            log.iol_user = user;

        }
    }
}
